package cn.iocoder.yudao.module.member.dal.mysql.device;

import cn.iocoder.yudao.framework.common.pojo.PageResult;
import cn.iocoder.yudao.framework.mybatis.core.mapper.BaseMapperX;
import cn.iocoder.yudao.framework.mybatis.core.query.LambdaQueryWrapperX;
import cn.iocoder.yudao.module.member.controller.admin.device.recrod.MemberDeviceRecordPageReqVO;
import cn.iocoder.yudao.module.member.controller.admin.point.vo.recrod.MemberPointRecordPageReqVO;
import cn.iocoder.yudao.module.member.controller.app.device.vo.AppMemberDeviceRecordPageReqVO;
import cn.iocoder.yudao.module.member.controller.app.point.vo.AppMemberPointRecordPageReqVO;
import cn.iocoder.yudao.module.member.dal.dataobject.device.MemberDeviceRecordDO;
import cn.iocoder.yudao.module.member.dal.dataobject.point.MemberPointRecordDO;
import org.apache.ibatis.annotations.Mapper;

import java.util.Set;

/**
 * 用户积分记录 Mapper
 *
 * @author QingX
 */
@Mapper
public interface MemberDeviceRecordMapper extends BaseMapperX<MemberDeviceRecordDO> {

    default PageResult<MemberDeviceRecordDO> selectPage(MemberDeviceRecordPageReqVO reqVO) {
        return selectPage(reqVO, new LambdaQueryWrapperX<MemberDeviceRecordDO>()
                .inIfPresent(MemberDeviceRecordDO::getUserId, reqVO.getUserIds())
                .eqIfPresent(MemberDeviceRecordDO::getFlag, reqVO.getFlag())
                .eqIfPresent(MemberDeviceRecordDO::getId, reqVO.getId())
                .orderByDesc(MemberDeviceRecordDO::getId));
    }

    default PageResult<MemberDeviceRecordDO> selectPage(Long userId, AppMemberDeviceRecordPageReqVO pageReqVO) {
        return selectPage(pageReqVO, new LambdaQueryWrapperX<MemberDeviceRecordDO>()
                .eq(MemberDeviceRecordDO::getUserId, userId)
                .betweenIfPresent(MemberDeviceRecordDO::getCreateTime, pageReqVO.getCreateTime())
                .gt(Boolean.TRUE.equals(pageReqVO.getAddStatus()),
                        MemberDeviceRecordDO::getDevice, 0)
                .lt(Boolean.FALSE.equals(pageReqVO.getAddStatus()),
                        MemberDeviceRecordDO::getDevice, 0)
                .orderByDesc(MemberDeviceRecordDO::getId));
    }

}
